<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <!-- <link rel="stylesheet" type="text/css" href="../static/Css/bootstrap.css" /> -->
    <!-- <link rel="stylesheet" type="text/css" href="../static/Css/bootstrap-responsive.css" /> -->
    <link rel="stylesheet" type="text/css" href="../static/Css/style.css" />
    <link rel="stylesheet" type="text/css" href="../static/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" type="text/css" href="../static/css/issue.css" />
    <script type="text/javascript" src="../static/Js/jquery.js"></script>
    <script type="text/javascript" src="../static/Js/jquery.sorted.js"></script>
    <script type="text/javascript" src="../static/Js/bootstrap.js"></script>
    <script type="text/javascript" src="../static/Js/ckform.js"></script>
    <script type="text/javascript" src="../static/Js/common.js"></script>
    <script type="text/javascript" src="../static/layer/layer.js"></script>
    <script type="text/javascript" src="../static/laydate/laydate.js"></script>

    <style type="text/css">
		#pname,#num{
		    width: 323px;
    		height: 38px;
		}
		

    </style>
</head>
<body>
	<div class="issuebox">
		<p>
			印染信息
		</p>
		<label>
			<span><em>*</em>姓名：</span>
			<input type="text" id="cusConName" placeholder="输入内容在15字以内" maxlength="25"/>
		</label>
		<label>
			<span><em>*</em>电话：</span>
    		<input placeholder='联系人电话' oninput='if(value.length>11)value=value.slice(0,11)' id='cusConPhone' style='padding: 5px 10px;outline: none;border: none; border-bottom: 1px solid #ccc;width: 200px' type='number'/>
		</label>
		<label class="">
			<span><em>*</em>公司名称：</span>
      		<input placeholder='公司名称' maxlength='25' id='cusName' style='padding: 5px 10px;outline: none;border: none; border-bottom: 1px solid #ccc;width: 200px' type='text'/>
		</label>
		<label>
			<span><em>*</em>公司地址：</span>
			<input placeholder='公司地址' maxlength='50' id='cusAddress' style='padding: 5px 10px;outline: none;border: none; border-bottom: 1px solid #ccc;width: 200px' type='text'/>
		</label>
		<label class="">
			<span><em>*</em>选择订单：</span>
      			<select id="orders">
			        <option value="0">请选择</option>
      			</select>
		</label>
		<label>
			<input style="cursor: pointer;" type="submit" id="subtn" value="添加印染"/>
		</label>
	</div>
	
</body>
</html>
<script type="text/javascript" >
laydate.render({
	  elem: '#wtime', //指定元素
	  type:'datetime'
	  //theme:'grid'
	});

	$(document).ready(function(){
		getOrders();
	});

	function getOrders(){
		$.ajax({
	      	type:"post",
	      	dataType:"json",
	      	url:"/order/getOrderList",
	      	data:{"content":""},	
	      	success:function(result){
	            if(result.ret == 1){
	            	var ol = result.list;
	            	console.log(ol);
	            	for(var i = 0;i < ol.length; i++){
	            		var ord = ol[i];
	            		if(ord.orderProcess == "外协"){
	            			$("#orders").append("<option value='"+ord.id+"'>"+ord.name+"</option>");	
	            		}else{
	            			layer.confirm('未找到需要印染的订单，请完成上一状态', {
	    	        			icon:3,
	    	        			btn: ['印染列表'] //按钮
	    	        			},function(){
	    	        				window.history.go(-1);
	    	        			});
	            		}	
	            	}
	            }else{
	            	ErrTips(result.msg);
	            }
	          },
	          error:function(result){
	        	  ErrTips("服务器错误");
	          }
	      })
	};
	
$(document).on('click','#subtn',function () {
		
        var name = $("#cusConName").val();
        var phone = $("#cusConPhone").val();
        var company = $("#cusName").val();
        var address = $("#cusAddress").val();
        var orderName = $('#orders option:selected').text();//选中的文本
		var orderId = $('#orders option:selected') .val();//选中的值
        
        if($.trim(name) == "" || $.trim(phone) == "" || $.trim(company) == "" || $.trim(address) == ""){
        	ErrTips("有未填写的信息");
            return;
        }
        
        $.ajax({
	      	type:"post",
	      	dataType:"json",
	      	url:"/customer/insertCustomer",
	      	data:{"name":name,"phone":phone,"company":company,"address":address,"orderId":orderId,"orderName":orderName},	
	      	success:function(result){
	      		if(result.ret == 1){
	            	layer.confirm('添加成功', {
	        			icon:3,
	        			btn: ['继续添加','印染列表'] //按钮
	        			}, function(){
	        				$("#cusConName").val("");
	        				$("#cusConPhone").val("");
	        				$("#cusName").val("");
	        				$("#cusAddress").val("");
	        				$("#orders").val(0);
	        				$("#rawInfo").val(0);
	        			},function(){
	        				window.history.go(-1);
	        			});
	            }else{
	            	ErrTips(result.msg);
	            }
	          },
	          error:function(result){
	        	  ErrTips("服务器错误");
	          }
	      })
    });

	function ErrTips(msg) {
		layer.msg(msg,{icon:7,time:1500});
    }
	
	function TureTips(msg) {
		layer.msg(msg,{icon:1,time:1500});
	}

</script>